package com.kuang.demo01;

/**买票问题，看线程安全
 * @author FHL
 */
public class TestThread4 implements Runnable {
    //有10张票
private int ticketNumber=10;
    @Override
    public void run() {
      while (true){
          if (ticketNumber<=0){
              break;
          }
          //模拟延时
          try {
              Thread.sleep(200);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println(Thread.currentThread().getName()+"拿到了第"+ticketNumber--+"张票！");
        }
    }
    public static void main(String[] args) {
        TestThread4 testThread4=new TestThread4();
new Thread(testThread4,"于毅").start();
new Thread(testThread4,"一清").start();
new Thread(testThread4,"四奥").start();
new Thread(testThread4,"之余").start();
    }
}
